package com.zc.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zc.order.client.CourseClient;
import com.zc.order.client.MemberClient;
import com.zc.order.entity.Order;
import com.zc.order.mapper.OrderMapper;
import com.zc.order.service.OrderService;
import com.zc.order.utils.OrderNoUtil;
import com.zc.utils.vo.CourseShowInfo;
import com.zc.utils.vo.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author cong
 * @since 2022-12-04
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

	@Autowired
	private CourseClient courseClient;

	@Autowired
	private MemberClient memberClient;

	@Override
	public String createOrder(String courseId, String memberId) {
		// 远程调用获取用户信息，课程信息
		CourseShowInfo courseInfoOrder = courseClient.getCourseInfoOrder(courseId);
		Member memberInfo = memberClient.getMemberInfo(memberId);

		Order order = new Order();
		order.setOrderNo(OrderNoUtil.getOrderNo());
		order.setCourseId(courseId);
		order.setCourseTitle(courseInfoOrder.getTitle());
		order.setCourseCover(courseInfoOrder.getCover());
		order.setTeacherName(courseInfoOrder.getTeacherName());
		order.setTotalFee(courseInfoOrder.getPrice());
		order.setMemberId(memberId);
		order.setMobile(memberInfo.getMobile());
		order.setNickname(memberInfo.getNickname());
		order.setStatus(0);
		order.setPayType(1);
		int insert = baseMapper.insert(order);
		return order.getOrderNo();
	}
}
